package com.zhaopin.mianshi;

import java.util.Stack;

/**
 * @author yin.peide
 * @date 2021-05-17 10:11
 * 括号 扩列
 */
public class bracketStack {

    public static void main(String[] args) {
        System.out.println(stackBoolean("{}"));
    }

    public static boolean stackBoolean(String str) {
        Stack<String> stack = new Stack();
        String[] strAttr = str.split("");

        for (int i = 0; i < strAttr.length; i++) {
            String s = strAttr[i];
            if (s.equals("(")
                    || s.equals("{")) {
                stack.push(s);
            }

            if (s.equals(")")) {
                String strPop = stack.pop();
                if (!strPop.equals("(")) {
                    return false;
                }
            }
            if (s.equals("}")) {
                String strPop = stack.pop();
                if (!strPop.equals("{")) {
                    return false;
                }
            }
        }
        if (stack.empty()){
            return true;
        }
        return false;



    }
}

